package com.iris.controller;

import com.iris.model.TestBean;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author : Iris.Xiao
 * @date : 2017/11/10 10:17
 * @description :
 */
@RestController
public class SleuthController {
    private static final Logger LOG = Logger.getLogger(SleuthController.class);
    @Autowired
    private RestTemplate restTemplate;

    @Bean
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

    @RequestMapping("/sleuthService2")
    public String sleuthService2(){
        LOG.log(Level.INFO, "sleuthService2");
        return restTemplate.getForObject("http://127.0.0.1:8763/hi?name=sdf", String.class);
    }
    @RequestMapping(value = "/sleuthBean",produces = { "application/json;charset=UTF-8" })
    public TestBean sleuthBean(){
        LOG.log(Level.INFO, "calling sleuthBean");
        return new TestBean("id","name",23);

    }

    @Bean
    public AlwaysSampler defaultSampler(){
        return new AlwaysSampler();
    }

}
